package com.hxx.day7.simple.front;

import com.hxx.day7.simple.controller.UserContoller;
import com.hxx.day7.simple.domain.User;

import java.util.List;
import java.util.Scanner;

public class UserFront {
        public static void main(String[] args) {
            //控制层
            UserContoller userContoller = new UserContoller();
            Scanner scanner = new Scanner(System.in);
            boolean flag = true;
            do {
                System.out.println("1.新增用户,2.更新用户,3.删除用户,4.查询所有用户,5.退出");
                int key = scanner.nextInt();
                switch (key){
                    case 1:
                        System.out.println("新增用户");
                        System.out.println("请输入用户id");
                        Integer id = scanner.nextInt();
                        System.out.println("请输入用户名");
                        String username = scanner.next();
                        System.out.println("请输入用户年龄");
                        Integer age = scanner.nextInt();
                        User user = new User(id,username,age);
                        userContoller.save(user);
                        break;
                    case 2:
                        System.out.println("更新用户");
                        System.out.println("请输入用户id");
                        id = scanner.nextInt();
                        System.out.println("请输入用户名");
                        username = scanner.next();
                        System.out.println("请输入用户年龄");
                        age = scanner.nextInt();
                        user = new User(id,username,age);
                        userContoller.update(user);
                        break;
                    case 3:
                        System.out.println("删除用户");
                        System.out.println("请输入用户id");
                        id = scanner.nextInt();
                        userContoller.delete(id);
                        break;
                    case 4:
                        System.out.println("查询所有用户");
                        List<User> list = userContoller.findAll();
                        for (User u : list) {
                            System.out.println(u);
                        }
                        break;
                    case 5:
                        System.out.println("退出");
                        flag = false;
                        break;
                }
            }while (flag);
        }
}




























